Searching outlink recursively

Hi Everyone,

I have a source module with multiple objects which in turn contains multiple links. User will be providing the name of the target module.

I need to traverse through each link from each of the objects in the source module recursively until I find out the name of the target module. The depth of the link could be 'n' number.

Please view the example in the attached file.

Lets take the first object in the Source Module.It has 3 links.We need to traverse through each of these links to its utmost depth to find out the target module.

Please find the code below. It traverses only single level of link for an object.Then , it jumps to next object.

string tempAttr
int countlinklevel = 0
bool matchedflag=false
Filter f = hasLinks(linkFilterOutgoing, "*")
set(M, f)
filtering on
for O in M do
{
O = current
for l in O -> "*" do
{
Trg1ModName = target (l)
justforOpen = fullName target (l)
adRec = create object type "Text" attribute srcModName
O.srcModName= "X"
while((countlinklevel<=100) && matchedflag == false)
{
print "New" Trg1ModName "\n"
if(cistrcmp(srcModName,Trg1ModName) == 0)
{
matchedflag = true
//print Trg1ModName "\n"
continue
}
else
{
Link lnk
string Trg1Mod
Module src = edit(justforOpen, false)
current = src
Filter f = hasLinks(linkFilterOutgoing, "*")
set(current, f)
filtering on
Object Obj = current
if(!null Obj)
for lnk in Obj -> "*" do
Trg1Mod = target(lnk)
if(!null Trg1Mod)
print Trg1Mod "\n"
}
countlinklevel = countlinklevel+1
}
matchedflag=false
}
}
filtering off
ack "Operations completed successfully"

Need help on this.Thanks in Advance

Regards
Raj
SystemAdmin - Fri Sep 25 13:41:28 EDT 2009

Re: Searching outlink recursively
llandale - Mon Sep 28 16:15:53 EDT 2009

Gads that's a mess.

If you surround youf code with StartBrace "code" EndBrace, looks like "{-code-}" without the dashes, then your posted code will look right with indents.

[1] Forget about getting the current Object. At line 9 you set "O = current" which will change the loop control variable, and in any case may get you the module is the module which is current at the time you execute that line. If you open some other module you will be setting O to the current object in THAT module.

[2] Forget about filtering the various modules. Just loop througn all "for O in entire mod do"; if (isDeleted(O)) continue", and then look for links.

[3] At the inner-most part of you code I think you missed some braces, and you want it to look like this:

if(!null Obj)
    {  for lnk in Obj -> "*" do
           {  Trg1Mod = target(lnk)
              if(!null Trg1Mod)
              {  print Trg1Mod "\n"
              }
           }
        }


[4] I think you need a Recursive function, not some sloppy while loop.

[5] I see you are only getting links to target modules that are already open; I think you probably want to get all modules, meaning your script will need to open them all.

Bla bla bla. I'd start again.

Run an analysis wizard to create a layout, then edit the DXL of the layout to see how it works.

 

 

  • Louie